function combineNum(arr, target) {
    // 终止条件
    arr.sort((a, b) => b - a)
    let cache = {}

    function genCombineNum(num) {
        // 终止条件
        if (num > target) {
            return 0
        }
        if (num === target) {
            return 1
        }
        if (cache[num] !== undefined) {
            return cache[num]
        }
        let temp = 0
        for (let i = 0; i < arr.length; i++) {
            const item = arr[i];
            temp += genCombineNum(num + item)
        }
        cache[num] = temp
        return temp
    }
    return genCombineNum(0)
}

console.log(combineNum([5, 1, 8], 24))